package com.china08.yxyapi.api.manage.sch.platform.website.setting;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.china08.yxyapi.api.YxyApiBaseController;
import com.china08.yxyapi.entity.db.sws.SwsSetting;
import com.china08.yxyapi.model.YxyApiReqModel;
import com.china08.yxyapi.model.YxyApiRespModel;
import com.china08.yxyapi.repository.db.SwsSettingRepository;

@CrossOrigin
@RestController("SwsSettingUpdSeoController")
public class SwsSettingUpdSeoController extends YxyApiBaseController {

    @Autowired
    private SwsSettingRepository swsSettingRepository;

    // 修改SEO优化
    @RequestMapping(value = "/api_yw/manage/sch/platform/website/setting/seo/upt", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public Object precess(HttpServletRequest request, HttpServletResponse response, @RequestBody(required = false) ReqModel reqModel) {
        String schoolId = getProfile(request, response).getSchoolId();
        String keywords = reqModel.keywords;
        String seoDescription = reqModel.seoDescription;

        Assert.isTrue(StringUtils.isNotBlank(schoolId), "修改对象为空");
        // Assert.isTrue(StringUtils.isNotBlank(keywords), "关键字不能为空");
        // Assert.isTrue(StringUtils.isNotBlank(seoDescription), "网站描述不能为空");

        SwsSetting swsSetting = swsSettingRepository.findBySchoolId(schoolId);
        swsSetting.setKeywords(keywords);
        swsSetting.setSeoDescription(seoDescription);
        swsSettingRepository.save(swsSetting);
        RespModel respModel = new RespModel();

        respModel.setMessage("成功");
        return respModel;
    }

    protected static class ReqModel extends YxyApiReqModel {

        public String schoolId;

        public String keywords;

        public String seoDescription;

    }

    protected static class RespModel extends YxyApiRespModel {

    }

}
